package cn.kgc.tangcco.vo;

import cn.hutool.core.util.IdcardUtil;
import cn.kgc.tangcco.pojo.Student;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.Date;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Accessors(chain = true)
public class StudentVo extends Student {
    private static final long serialVersionUID = 1011794508788308965L;
    /**
     * 性别 1代表男性 0代表女性
     */
    @TableField(value="gender")
    private Integer gender;
    /**
     * 总人数
     */
    @TableField(value="total")
    private Integer total;

    /**
     * 出生日期
     */
    @TableField(value="birthday")
    @JSONField(format = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 年龄
     */
    @TableField(value="age")
    private Integer age;

    public void convertIdCard(){
        if (this.getIdCard() != null) {
            this.setBirthday(IdcardUtil.getBirthDate(this.getIdCard()));
            this.setAge(IdcardUtil.getAgeByIdCard(this.getIdCard()));
            this.setGender(IdcardUtil.getGenderByIdCard(this.getIdCard()));
        }
    }

}
